package com.shark.springbootcms.controller;

import com.shark.springbootcms.common.Result;
import com.shark.springbootcms.form.PermsForm;
import com.shark.springbootcms.form.UserForm;
import com.shark.springbootcms.model.Role;
import com.shark.springbootcms.model.User;
import com.shark.springbootcms.service.RoleService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @RequestMapping("/list")
    public Result list(UserForm form) {
        return roleService.list(form);
    }


    @PostMapping("/add")
    public Result addRole(@RequestBody Role form) {
        return roleService.addRole(form);

    }

    @PostMapping("/edit/{id}")
    public Result edit(@RequestBody Role role, @PathVariable("id") String id) {
        return roleService.edit(role, id);
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id") String id) {
        return roleService.delete(id);
    }

    @GetMapping("/perms")
    public Result perms(String roleId) {
        return roleService.perms(roleId);
    }

    @PostMapping("/addPerms")
    public Result perms( @RequestBody PermsForm form) {
        return roleService.addPerms(form);
    }

}
